<?php


class Utilities {

	
	/**
	 * Retorna el objeto Manage con sus propiedades seteadas
	 */
	public static function curPageURL() {
		$pageURL = 'http';
		if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
			$pageURL .= "://";
		if ($_SERVER["SERVER_PORT"] != "80") {
			$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
		} else {
			$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
		}
		return $pageURL;
	}

	
	/**
	 * Retorna la lista de $messages internacionalizada
	 * @param Smarty $smarty
	 * @param List<Message> $messages
	 * @return List<Message> $i18nMessages
	 */
	public static function i18nMessages($smarty, $messages) {
		$i18nMessages = array();
		foreach($messages as $message) {
			if (Validation::isEmptyString($message['text']))
				$message['text'] = $smarty->get_config_vars($message['code']);
			$i18nMessages[] = $message;
		}
		return $i18nMessages;		
	}
	
	
	/**
	 * Retorna true si el $text termina en $test
	 * @param String $string
	 * @param String $test
	 * @return boolean
	 */
	public static function endsWith($string, $test) {
	    $strlen = strlen($string);
	    $testlen = strlen($test);
	    if ($testlen > $strlen) return false;
	    return substr_compare($string, $test, -$testlen) === 0;
	}
	

	/**
	 * Retorna la extension de un archivo
	 * @param String $fileName
	 * @return extension
	 */	
	public static function getFileExtension($fileName) {
		return substr(strrchr($fileName,'.'),1);
	}
	
}
?>